package com.itheima.bos.service.take_delivery.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.bos.dao.base.PromotionRepositoyry;
import com.itheima.bos.domain.take_delivery.PageBean;
import com.itheima.bos.domain.take_delivery.Promotion;
import com.itheima.bos.service.take_delivery.IPromotionService;
@Service
@Transactional
public class PromotionServiceImpl implements IPromotionService {
	@Autowired
	private PromotionRepositoyry promotionRepositoyry;
	
	@Override
	public void save(Promotion model) {
		promotionRepositoyry.save(model);
	}

	@Override
	public Page<Promotion> findAll(Pageable pageable) {
		
		return promotionRepositoyry.findAll(pageable);
	}

	@Override
	public PageBean<Promotion> findPageData(int page, int rows) {
		//创建pageable对象
		Pageable pageable = new PageRequest(page-1, rows);
		Page<Promotion> pageData = promotionRepositoyry.findAll(pageable);
		//创建pageBean封装数据
		PageBean<Promotion> pageBean = new PageBean<Promotion>();
		pageBean.setPageData(pageData.getContent());
		pageBean.setTotalCount(pageData.getTotalElements());
		
		return pageBean;
	}

	@Override
	public Promotion findById(Integer id) {
		
		return promotionRepositoyry.findOne(id);
	}

}
